package com.scaffold.util;

import com.auth0.jwt.JWTSigner;
import com.auth0.jwt.JWTVerifier;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Da Shuai
 * @since 2021-08-17 18:46:46
 */
public class JwtUtil {

    public static String TOKEN_KEY = "token";

    public static String SECRET = "no_bug";

    public static String TOKEN_KEY_USER_ID = "userId";

    public static Map<String, Object> validateToken(String token) {
        try {
            JWTVerifier verifier = new JWTVerifier(SECRET);
            return verifier.verify(token);
        } catch (Exception e) {

            //log.error(e.getMessage(), e);
            return new HashMap<>(0);
        }
    }

    public static String generateToken(Map<String, Object> map) {
        JWTSigner signer = new JWTSigner(SECRET);
        JWTSigner.Options options = new JWTSigner.Options();
        options.setIssuedAt(true);
        return signer.sign(map, options);
    }
}
